<!-- 添加分区-绘制分区 -->
<template>
  <el-dialog :visible.sync="dialogVisiblePartition" :before-close="handleCloseBindWarnStandardPartition" :close-on-click-modal="false" :title="title" width="600px" height="300px">
    <el-form v-loading="formLoading" ref="dialogFormPartition" :model="dialogFormPartition" :rules="rules" label-width="120px">
      <el-form-item label="所属单位">
        <el-input v-model="subordinateUnit" class="el-disabled" readonly="readonly"/>
      </el-form-item>
      <el-form-item label="所属建筑群" prop="park_name">
        <el-input v-model="dialogFormPartition.park_name" class="el-disabled" readonly="readonly"/>
      </el-form-item>
      <el-form-item label="所属建筑" prop="building_name">
        <el-input v-model="dialogFormPartition.building_name" class="el-disabled" readonly="readonly"/>
      </el-form-item>
      <el-form-item label="所属楼层" prop="floor_name">
        <el-input v-model="dialogFormPartition.floor_name" class="el-disabled" readonly="readonly"/>
      </el-form-item>
      <el-form-item label="分区名称" prop="partition_name">
        <el-input v-model="dialogFormPartition.partition_name" placeholder="请输入分区名称" autocomplete="off"/>
      </el-form-item>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button type="primary" @click="submitFormPartition">确 定</el-button>
      <el-button @click="handleCancelPartition">取 消</el-button>
    </div>
  </el-dialog>
</template>
<script>
// import { usersAdd } from '@/api/users'
const statusMap = {
  10: '单位10',
  12: '单位12',
  20: '单位20',
  30: '单位30',
  40: '单位40',
  50: '单位50',
  60: '单位60',
  70: '单位70',
  80: '单位80',
  90: '单位90'
}
export default {
  props: {
    dialogVisiblePartition: {
      type: Boolean,
      default: () => {
        return false
      }
    },
    dialogFormPartition: {
      type: Object,
      default: () => {
        return {}
      }
    }
  },
  data() {
    return {
      title: '',
      subordinateUnit: '上海励尔信息科技有限公司/本单位',
      statusMap,
      equipmentSystem: this.GLOBAL.equipmentSystem,
      // 添加form验证
      rules: {
        park_name: [{
          required: true,
          message: '请选择建筑群',
          trigger: 'change'
        }],
        building_name: [{
          required: true,
          message: '请选择建筑',
          trigger: 'change'
        }],
        floor_name: [{
          required: true,
          message: '请选择层楼',
          trigger: 'change'
        }],
        partition_name: [{
          required: true,
          message: '请输入分区',
          trigger: 'change'
        }]
      },
      formLoading: false
    }
  },
  computed: {
  },
  created() {
    this.title = '添加分区'
  },
  methods: {
    submitFormPartition(val) {
      this.$refs['dialogFormPartition'].validate((valid) => {
        if (valid) {
          const that = this
          that.$message.success('添加成功！')
          that.$emit('submitFormPartition', this.dialogFormPartition)
          // that.formLoading = true
          // var params = {
          //   // userId: this.userInfo.userCode,
          //   ...that.dialogFormPartition
          // }
          // usersAdd(params)
          //   .then((res) => {
          //     that.formLoading = false
          //     this.dialogVisiblePartition = false
          //     const data = res.data
          //     if (data.code === 40000) {
          //       that.$message.success(data.messageContent)
          //       that.$emit('submitFormPartition', this.dialogFormPartition)
          //     } else {
          //       that.$message.warning(data.messageContent)
          //     }
          //   })
          //   .catch((err) => {
          //     console.log(err)
          //     that.formLoading = false
          //   })
        }
      })
    },
    // 关闭弹窗
    handleCancelPartition() {
      this.$emit('getCancelPartition')
    },
    // 关闭弹窗，不可以删这个方法。不用这个方法点击遮罩层关闭会报错
    handleCloseBindWarnStandardPartition() {
      this.$emit('closeBindWarnStandardPartition')
    }
  }
}
</script>
<style rel="stylesheet/scss" lang="scss" scoped>
</style>
